/**
 * 
 */
package leetCode;

/**
 * @author zhong
 *
 */
public class PrimeNumberofSetBitsinBinaryRepresentation {
	public int countPrimeSetBits(int L, int R) {
		int res = 0;
		for (int i = L; i <= R; i++) {
			if (isPrime(Integer.bitCount(i))) {
				res++;
			}
		}
		return res;
	}

	private boolean isPrime(int bitCount) {
		if (bitCount == 1) {
			return false;
		}
		for (int i = 2; i <= bitCount / 2; i++) {
			if (bitCount % i == 0) {
				return false;
			}
		}
		return true;
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		int L = 10, R = 15;
		System.out.println(new PrimeNumberofSetBitsinBinaryRepresentation().countPrimeSetBits(L, R));
	}

}
